package com.cirkana.viewer.route;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import android.content.res.AssetManager;

public class RoutesUtil {

	private static final String ROUTES_PATH = "gpx";
	private static final String ROUTES_PREFIX = ".gpx";

	public static String[] getLocalRoutes(AssetManager assetManager) {
		List<String> routes = new ArrayList<String>();
		String[] gpxs = {};
		try {
			gpxs = assetManager.list(ROUTES_PATH);
		} catch (IOException e) {
			e.printStackTrace();
		}
		for (String f : gpxs)
			if (f.toLowerCase().endsWith(ROUTES_PREFIX.toLowerCase()))
				routes.add(f);
		return routes.toArray(new String[routes.size()]);
	}
	
	public static InputStream openLocalRoute(AssetManager assetManager, String fileName) throws IOException {
		return assetManager.open(ROUTES_PATH + "/" + fileName);
	}

}
